home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Games of Daze
/
Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso
/
x2ftp
/
msdos
/
gamesrc
/
arasan_s
/
srclimit.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1994-07-31
|
6KB
|
208 lines
// Copyright 1994 by Jon Dart. All Rights Reserved.
#include "srclimit.h"
#include "srclimt2.h"
#include "constant.h"
#include <wpglob.h>
#define IDP_SEARCHTYPE 101
#define IDP_FIXEDPLY 102
#define IDP_TIMELIMIT 103
#define IDP_GAME_LIMIT 104
#define IDP_TOURNAMENT 105
#define IDP_MOVES_OR_PLY 108
#define IDP_MINUTES 109
#define IDP_PLY_TEXT 110
#define IDP_MINUTES_TEXT 111
#define IDP_SECONDARY 112
WPControlMap SearchLimitDialog::ControlMap[] =
{
cmRBgp( IDP_SEARCHTYPE, Search_Limit_Options, search_type, 4 )
cmEdit( IDP_MOVES_OR_PLY, Search_Limit_Options, move_or_ply )
cmEdit( IDP_MINUTES, Search_Limit_Options, time_limit )
cmEnd( IDP_SEARCHTYPE )
};
Search_Limit_Options::Search_Limit_Options()
{
}
Search_Limit_Options::Search_Limit_Options( const Time_Control &tc,
const Control c )
{
const Search_Limit limit = tc.get_search_limit();
switch (tc.get_search_type())
{
case Fixed_Ply:
search_type = 0;
wsprintf(move_or_ply,"%d",
limit.max_ply);
time_limit[0] = '\0';
break;
case Time_Limit:
search_type = (c == First) ? 1 : 0;
wsprintf(move_or_ply,"%ld",
limit.seconds);
time_limit[0] = '\0';
break;
case Game:
search_type = (c == First) ? 2 : 1;
wsprintf(move_or_ply,"%d",
limit.limit.minutes);
time_limit[0] = '\0';
break;
case Tournament:
search_type = (c == First) ? 3 : 2;
wsprintf(move_or_ply,"%d",
limit.limit.moves);
wsprintf(time_limit,"%d",
limit.limit.minutes);
break;
case None:
search_type = (c == First) ? 4 : 0;
*time_limit = *move_or_ply = '\0';
break;
}
}
Boolean Search_Limit_Options::parse(Time_Control &tc, const Control c)
{
int minutes, moves;
char msg[100];
Search_Limit limit;
int index = search_type;
if (c == Second)
{
// The secondary search dialog has buttons that don't correspond
// in order to the enum Search_Type. So compensate for that here:
static int indexes[] = { 4, 2, 3, 0, 0 };
index = indexes[search_type];
#ifdef RANGE_CHECK
assert(index != 0);
#endif
}
switch (index)
{
case 0: /* Fixed_Ply */
limit.max_ply = atoi(move_or_ply);
if (limit.max_ply <= 0) limit.max_ply = 2;
if (limit.max_ply > Constants::MaxPly)
limit.max_ply = Constants::MaxPly;
break;
case 1: /* Time_Limit */
{
unsigned long seconds = atol(move_or_ply);
limit.seconds = seconds;
break;
}
case 2: /* Game */
{
int minutes = atoi(move_or_ply);
limit.limit.minutes = minutes;
break;
}
case 3: /* Tournament */
moves = atoi(move_or_ply);
minutes = atoi(time_limit);
if (moves && minutes)
{
limit.limit.moves = moves;
limit.limit.minutes = minutes;
}
break;
}
tc.set_search_type((Search_Type)index);
tc.set_search_limit(limit);
return True;
}
SearchLimitDialog::SearchLimitDialog(WPWin *pwin,
Search_Limit_Options *primary_options,
Search_Limit_Options *secndry_options)
: initial_search_type(primary_options->search_type),
WPDialogModal("SEARCHLIMITS", pwin, ControlMap, primary_options)
{
secondary_options = secndry_options;
createWin();
}
void SearchLimitDialog::initDlg()
{
// Note: the Windows++ getControl function appears not to return valid
// data, at least when called from here, so we limit ourselves to direct
// Windows calls
const HWND hDlg = getHwnd();
hPly_text = GetDlgItem(hDlg,IDP_PLY_TEXT);
hMinutes_field = GetDlgItem(hDlg,IDP_MINUTES);
hMinutes_text = GetDlgItem(hDlg,IDP_MINUTES_TEXT);
hSecondary = GetDlgItem(hDlg,IDP_SECONDARY);
new_type(initial_search_type);
}
void SearchLimitDialog::new_type(int srctype)
{
assert(srctype < 4);
switch (srctype)
{
case 0:
ShowWindow(hMinutes_field,SW_HIDE);
ShowWindow(hMinutes_text,SW_HIDE);
EnableWindow(hMinutes_text,FALSE);
SetWindowText(hPly_text,"Ply:");
EnableWindow(hSecondary,FALSE);
break;
case 1:
ShowWindow(hMinutes_field,SW_HIDE);
ShowWindow(hMinutes_text,SW_HIDE);
EnableWindow(hMinutes_text,FALSE);
SetWindowText(hPly_text,"Seconds/Move:");
EnableWindow(hSecondary,FALSE);
break;
case 2:
ShowWindow(hMinutes_field,SW_HIDE);
ShowWindow(hMinutes_text,SW_HIDE);
EnableWindow(hMinutes_text,FALSE);
SetWindowText(hPly_text,"Minutes/Game");
EnableWindow(hSecondary,FALSE);
break;
case 3:
ShowWindow(hMinutes_field,SW_SHOWNORMAL);
ShowWindow(hMinutes_text,SW_SHOWNORMAL);
EnableWindow(hMinutes_text,TRUE);
// show the label "Moves:" instead of "Ply:"
SetWindowText(hPly_text,"Moves:");
EnableWindow(hSecondary,TRUE);
break;
}
}
BOOL SearchLimitDialog::command(int id, WORD msg)
{
switch (id)
{
case IDP_FIXEDPLY:
new_type(0);
break;
case IDP_TIMELIMIT:
new_type(1);
break;
case IDP_GAME_LIMIT:
new_type(2);
break;
case IDP_TOURNAMENT:
new_type(3);
break;
case IDP_SECONDARY:
{
SecondaryLimitDialog *aDlg = new SecondaryLimitDialog(this,
secondary_options);
delete aDlg;
break;
}
default:
break;
}
return WPDialogModal::command(id, msg);
}